<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['worker']=$this->model('model')->checkworker();
if($_RQ['op']=='main'){
	$return['ischecklogin']=model('jy_weishop/member')->checklogin('','','','',true);
	$status=intval($_RQ['status']);
	$return['list']=array();
	$return['params']=array('status'=>$status,'y'=>'','m'=>'');
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$lastdaytime = $daytime-24*3600;
	$data['inall0']=pdo_getsum('jy_shopworker_orderlog',array('status'=>0,'uniacid'=>$_SESSION['uniacid']),'price');
	$data['inall']=pdo_getsum('jy_shopworker_orderlog',array('status'=>1,'uniacid'=>$_SESSION['uniacid']),'price');
	$data['inday']=pdo_getsum('jy_shopworker_orderlog',array('status'=>1,'uniacid'=>$_SESSION['uniacid'],'createtime >'=>$daytime),'price');
	$data['inlastday']=pdo_getsum('jy_shopworker_orderlog',array('status'=>1,'uniacid'=>$_SESSION['uniacid'],'createtime between'=>array($lastdaytime,$daytime)),'price');
	$data['beninall']=pdo_getsum('jy_shopworker_orderlog',array('status'=>1,'uniacid'=>$_SESSION['uniacid']),'benprice');
	$data['beninday']=pdo_getsum('jy_shopworker_orderlog',array('status'=>1,'uniacid'=>$_SESSION['uniacid'],'createtime >'=>$daytime),'benprice');
	$data['beninlastday']=pdo_getsum('jy_shopworker_orderlog',array('status'=>1,'uniacid'=>$_SESSION['uniacid'],'createtime between'=>array($lastdaytime,$daytime)),'benprice');
	$return['data']=$data;
	$member=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit5','credit6','mobile','avatar','nickname'));
	$return['member']=$member;
	$return['psize']=20;
	if(!empty($_RQ['y'])){
		$return['params']['y']=$_RQ['y'];
	}
	if(!empty($_RQ['m'])){
		$return['params']['m']=$_RQ['m'];
	}
	$nowy=date('Y');
	$y1=$nowy-2;
	$y2=$nowy-1;
	$return['ys']=array(
		$y1=>$y1.'年',
		$y2=>$y2.'年',
		$nowy=>$nowy.'年',
	);
	$return['months']=array(
		'01'=>'1月',
		'02'=>'2月',
		'03'=>'3月',
		'04'=>'4月',
		'05'=>'5月',
		'06'=>'6月',
		'07'=>'7月',
		'08'=>'8月',
		'09'=>'9月',
		'10'=>'10月',
		'11'=>'11月',
		'12'=>'12月',
	);
	set_html('title','业绩明细');
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$params['status']=intval($_RQ['status']);
	if(!empty($_RQ['y']) && !empty($_RQ['m'])){
		$yuestart = mktime(0,0,0,$_RQ['m'],1,$_RQ['y']);
		$yueend = mktime(0,0,0,$_RQ['m']+1,1,$_RQ['y']);
		$params['pay_time between']=array($yuestart,$yueend);
	}elseif(!empty($_RQ['y'])){
		$yuestart = mktime(0,0,0,1,1,$_RQ['y']);
		$yueend = mktime(0,0,0,1,1,$_RQ['y']+1);
		$params['pay_time between']=array($yuestart,$yueend);
	}
	if($_RQ['title']){
		$params2=array('uniacid'=>$_SESSION['uniacid']);
		$params2['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
		$workerid=pdo_getall('jy_shopworker_list',$params2,array('title','id'),'id');
		if($workerid){
			$workerid=array_keys($workerid);
		}else{
			$workerid=-1;
		}
		$params['workerid']=$workerid;
	}
	if($_RQ['cname']){
		$params['cname like']='%'.trim($_RQ['cname']).'%';
		$return['params']['cname']=$_RQ['cname'];
	}
	if($_RQ['mobile']){
		$params['mobile like']='%'.trim($_RQ['mobile']).'%';
		$return['params']['mobile']=$_RQ['mobile'];
	}
	if($_RQ['username']){
		$params['username like']='%'.trim($_RQ['username']).'%';
		$return['params']['username']=$_RQ['username'];
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=pdo_getlist('jy_shopworker_orderlog',$parameter);
	if(!$list){
		exi('none');
	}
	foreach($list as &$item){
		$item['workertitle']=pdo_getcolumn('jy_shopworker_list',array('id'=>$item['workerid'],'uniacid'=>$_SESSION['uniacid']),'title');
		$item['statustitle']=$this->orderlog_status[$item['status']];	
		$item['goodsinfo']=json_decode($item['goodsinfo'],true);
		$item['payimgs']=array($item['payimg']);
		$item['pay_time']=date('Y-m-d H:i',$item['pay_time']);
		$item['createtime']=date('Y-m-d H:i',$item['createtime']);
	}
	exi($list);
}
if($_RQ['op']=='sheck'){
	if($_RQ['postdata']){
		$postdata=get_postdata();
		$data=array(
			'status'=>trim($postdata['status']),
			'upworkerid'=>$return['worker']['id'],
			'failremark'=>trim($postdata['failremark']),
		);
		$id=intval($postdata['id']);
		if($id){
			pdo_update('jy_shopworker_orderlog',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			exi('审批成功！','','/orderlog_check/');
		}else{
			exi('没有找到审批');
	}
	}
	$id=intval($_RQ['id']);
	$item=pdo_get('jy_shopworker_orderlog',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$item['goodsinfo']=json_decode($item['goodsinfo'],true);
	$item['lifee']=price($item['price']-$item['benprice'],'int');
	$return['item']=$item;
	$return['htmls']=array(
			'type'=>'edit',
			'edit'=>array(
				array('name'=>'goodsinfo.title','title'=>'商品名称','type'=>'copy'),
				array('name'=>'price','title'=>'销售价','type'=>'copy'),
				array('name'=>'lifee','title'=>'利润','type'=>'copy'),
				array('name'=>'benprice','title'=>'当时成本价','type'=>'copy'),
				array('name'=>'payimg','title'=>'支付凭证','type'=>'img_show'),
				array('name'=>'ordersn','title'=>'支付单号','type'=>'copy'),
				array('name'=>'cname','title'=>'企业名称','type'=>'copy'),
				array('name'=>'username','title'=>'联系人姓名','type'=>'copy'),
				array('name'=>'mobile','title'=>'联系人电话','type'=>'copy'),
				array('name'=>'status','title'=>'审批状态','type'=>'radio','options'=>'status'),
				array('name'=>'failremark','title'=>'审核不通过原因','type'=>'text','show'=>array('status'=>2)),
			),
	);
	$return['status']=array('待审核','审核通过','审核不通过');
	exi($return);
}
?>